package cn.xshi.sys.web;

import cn.xshi.common.annotation.Auth;
import cn.xshi.common.base.BaseAction;
import cn.xshi.common.base.BasePage;
import cn.xshi.common.base.BaseResult;
import cn.xshi.common.base.BaseSearch;
import cn.xshi.common.util.StringUtil;
import cn.xshi.sys.model.SysConcordat;
import cn.xshi.sys.service.SysConcordatService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Desc 合同管理
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@RestController
@RequestMapping("/sysConcordat")
@Api(value = "合同API",tags = "合同API",description = "合同API")
public class SysConcordatController extends BaseAction {

	@Resource
	private SysConcordatService sysConcordatService;

	/**
	 * 加载初始化列表数据并分页
	 * @param baseSearch
	 */
	@ApiOperation(value="查询合同列表并分页", notes="查询合同列表并分页")
	@PostMapping(value="/list")
	@Auth(value = "/sysConcordat/list",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	public BasePage<List<SysConcordat>> getSysConcordatListByCondition(@RequestBody(required=true) BaseSearch baseSearch){
		Map<String, Object> condition = baseSearch.convert();
		commonHPager(baseSearch);
		List<SysConcordat> sysConcordatList = sysConcordatService.getSysConcordatListByCondition(condition);
		PageInfo<SysConcordat> page = new PageInfo<SysConcordat>(sysConcordatList);
		return outPageBootStr(page,baseSearch);
	}

	/**
	 * 查询单个合同
	 * @param SysConcordatId
	 */
	@ApiOperation(value="查询单个合同", notes="查询单个合同")
	@GetMapping(value="/get/{SysConcordatId}")
	@Auth(value = "/sysConcordat/get",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	public BaseResult<SysConcordat> getSysConcordatById(@PathVariable("SysConcordatId") String SysConcordatId){
		SysConcordat sysConcordat = sysConcordatService.getSysConcordatById(SysConcordatId);
		return outDataStr(sysConcordat);
	}

	/**
	 * 添加
	 * @param sysConcordat
	 */
	@PostMapping(value="/add")
	@ApiOperation(value="创建单个合同", notes="创建单个合同")
	public BaseResult addSysConcordat(@RequestBody SysConcordat sysConcordat){
		int i = 0;
		if(null != sysConcordat){
			i= sysConcordatService.addSysConcordat(sysConcordat);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 修改
	 * @param sysConcordat
	 */
	@PutMapping(value="/update")
	@ApiOperation(value="编辑单个合同", notes="编辑单个合同")
	public BaseResult updateSysConcordat(@RequestBody SysConcordat sysConcordat){
		int i = 0;
		if(null != sysConcordat){
			i= sysConcordatService.updateSysConcordat(sysConcordat);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 删除
	 * @param id
	 */
	@DeleteMapping(value="/delete")
	@ApiOperation(value="删除合同", notes="删除合同")
	public BaseResult delSysConcordat(String id){
		int i = 0;
		if(!StringUtil.isEmpty(id)){
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("id",id.split(","));
			i= sysConcordatService.delSysConcordat(condition);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}
}
